package com.bwie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bwie.pojo.TbActivity;
import com.bwie.pojo.TbPrize;
import com.bwie.pojo.Tblotto;
import com.bwie.pojo.Tbprav;
import com.bwie.service.impl.TbAcitvityServiceImpl;
import com.bwie.service.impl.TblottoServiceImpl;
import com.bwie.service.impl.TbpravServiceImpl;
import com.bwie.service.impl.TbprizeServiceImpl;
import com.bwie.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/getnum/prize")
@Slf4j
public class PrizeController {
    //奖品表
    @Autowired
    TbprizeServiceImpl tbprizeService;
    //活动表
    @Autowired
    TbAcitvityServiceImpl tbAcitvityService;
    //记录表
    @Autowired
    TblottoServiceImpl tblottoService;
    //活动奖品关联表
    @Autowired
    TbpravServiceImpl tbpravService;

    /**
     * 日志打印
     */
    private static final Logger logger = LoggerFactory.getLogger(PrizeController.class);

    /**
     * 获取活动数据
     */
    @GetMapping("/getactivity/{aid}")
    public R GetActivity(@PathVariable(value = "aid") String aid){
        TbActivity Acitvity = tbAcitvityService.getById(aid);
        List<Tbprav> list = tbpravService.list(new LambdaQueryWrapper<Tbprav>().eq(Tbprav::getActivityId, aid));
        ArrayList<String> strings = new ArrayList<>();
        for (Tbprav tbprav : list) {
            String prizeId = tbprav.getPrizeId();
            strings.add(prizeId);
        }
        List<TbPrize> prizeList = null;
        if (strings.size()!=0){
            prizeList = tbprizeService.list(new LambdaQueryWrapper<TbPrize>().in(TbPrize::getPrizeId, strings));
        }

        HashMap<String, Object> activityPrizeValue = new HashMap<>();
        activityPrizeValue.put("activity",Acitvity);
        activityPrizeValue.put("prizeList",prizeList);
        return R.OK(activityPrizeValue);
    }
}
